import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import 'bootstrap'
import 'bootstrap/dist/css/bootstrap.css'

import axios from 'axios'

Vue.prototype.$http = axios
// axios.defaults.baseURL = "/api";
// axios.defaults.baseURL = 'http://localhost:9090'
axios.defaults.baseURL = 'http://yongyan0624.top:9091'

import './assets/common.css'

// 重写Element UI 的消息框  显示时间
Vue.prototype.$message = function(msg) {
  Message(msg)
}
Vue.prototype.$message = function(msg) {
  return Message({
    message: msg,
    duration: 1000,
  })
}
Vue.prototype.$message.success = function(msg) {
  return Message.success({
    message: msg,
    duration: 1000,
  })
}
Vue.prototype.$message.warning = function(msg) {
  return Message.warning({
    message: msg,
    duration: 1000,
  })
}

Vue.use(ElementUI)
Vue.config.productionTip = false

/*拦截器 */
axios.interceptors.request.use(
  (config) => {
    config.headers.Authorization = window.sessionStorage.getItem('token')
    return config
  },
  (error) => {
    return { code: 400, message: '请求错误' }
  }
)

axios.interceptors.response.use(
  (config) => {
    return config.data
  },
  (error) => {
    return { code: 400, message: '权限不足或未登录' }
  }
)

new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount('#app')
